//
//  CustomWuLiuView.m
//  Experss
//
//  Created by 嗯，大葱 on 17/8/2.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "CustomWuLiuView.h"
#import "ShangpinVCell.h"

@implementation CustomWuLiuView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5f];

   
   
      
    }
    return self;
}
- (void)setTitArray:(NSArray *)titArray {
    _titArray = titArray;
    [self configureView2];
}
- (void)configureView2 {
    
    UIButton *btn = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn.frame = CGRectMake(0, 0, kScreen_Width, kView_Height-350);
    btn.backgroundColor = [UIColor clearColor];
    [btn addTarget:self action:@selector(handleRePopView:) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:btn];
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kView_Height-350, kView_Width, 350) style:(UITableViewStylePlain)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_tableView];
    [_tableView registerNib:[UINib nibWithNibName:@"ShangpinVCell" bundle:nil] forCellReuseIdentifier:@"ShangpinVCell"];
    _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    _tableView.separatorStyle = kSpNone;
    _tableView.scrollEnabled = NO;
    
    
    //确认购买按钮
    UIButton *buyBtn =[UIButton buttonWithType:(UIButtonTypeCustom)];
    buyBtn.frame = CGRectMake(0, CGRectGetMaxY(_tableView.frame)- 50, kView_Width, 50);
    [buyBtn setTitle:@"确定" forState:(UIControlStateNormal)];
    [buyBtn setBackgroundImage:[UIImage imageNamed:@"bg1"] forState:(UIControlStateNormal)];
    [self addSubview:buyBtn];
    
    [buyBtn addTarget:self action:@selector(handleBuyBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   return  _titArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 50;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *bgV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 50)];
    
    bgV.backgroundColor = [UIColor whiteColor];
    
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 50)];
    label.text = @"商品参数";
    label.textColor = [UIColor blackColor];
    label.textAlignment = NSTextAlignmentCenter;
    [bgV addSubview:label];
    return bgV;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ShangpinVCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShangpinVCell"];
    cell.selectionStyle = kSeNone;
    cell.titlB.text = self.titArray[indexPath.row][@"name"];
    cell.conLB.text=self.titArray[indexPath.row][@"attr_value"];
    return cell;
    
}
//回收视图
- (void)handleRePopView:(UIButton *)sender {

    if(self.delegate && [self.delegate respondsToSelector:@selector(rePopShangpinXiangQingView:)])
    {
        [self.delegate rePopShangpinXiangQingView:sender];
    }
}

//确认按钮点击事件
- (void)handleBuyBtnAction :(UIButton *)sender {
    if(self.delegate && [self.delegate respondsToSelector:@selector(sureShangPinCanshuView:)])
    {
        [self.delegate sureShangPinCanshuView:sender];
    }
}

@end
